//
//  YXOrderView.m
//  跑跑快销
//
//  Created by 杨潇 on 14-5-4.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "YXOrderView.h"

@implementation YXOrderView
@synthesize calendar,tabView,cashLab,chargesales,reach;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor lightGrayColor];
        
        NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        calendar = [UIButton buttonWithType:UIButtonTypeSystem];
        [calendar setTitle:[formatter stringFromDate:[NSDate date]] forState:UIControlStateNormal];
        calendar.backgroundColor = [UIColor whiteColor];
        calendar.frame = CGRectMake(0, 0, 320, 40);
        [self addSubview:calendar];
        
        CGRect titleLabRect;
        float titleW = 320.0/3;
        NSArray * titleArr = [NSArray arrayWithObjects:@"客户名",@"总金额(元)",@"退货", nil];
        for (int i = 0; i < 3; i ++) {
            UILabel * titleLab = [[UILabel alloc] initWithFrame:CGRectMake(titleW * i, calendar.frame.origin.y + calendar.frame.size.height, titleW, 30)];
            titleLab.text = [titleArr objectAtIndex:i];
            titleLab.textAlignment = NSTextAlignmentCenter;
            titleLab.backgroundColor = [UIColor clearColor];
            titleLab.layer.borderColor = [UIColor blackColor].CGColor;
            titleLab.layer.borderWidth = .5;
            [self addSubview:titleLab];
            titleLabRect = titleLab.frame;
        }
        
        int startY = STARTY;
        tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, titleLabRect.origin.y + titleLabRect.size.height, 320, [UIScreen mainScreen].bounds.size.height - startY - 70 - 50) style:UITableViewStylePlain];
        tabView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tabView.bounces = NO;
        [self addSubview:tabView];
        
        UIView * downVi = [[UIView alloc] initWithFrame:CGRectMake(0, tabView.frame.origin.y + tabView.frame.size.height, 320, 50)];
        downVi.layer.borderColor = [UIColor blackColor].CGColor;
        downVi.layer.borderWidth = .5;
        [self addSubview:downVi];
        
        NSArray * titleArr1 = [NSArray arrayWithObjects:@"现金(元)\r\n",@"赊销(元)\r\n",@"日达成(%)\r\n", nil];
        cashLab = [[UILabel alloc] init];
        chargesales = [[UILabel alloc] init];
        reach = [[UILabel alloc] init];
        NSArray * labArr = [NSArray arrayWithObjects:cashLab,chargesales,reach, nil];
        for (int i = 0; i < 3; i ++) {
            if (i != 2) {
                UIView * blackVi = [[UIView alloc] initWithFrame:CGRectMake(titleW*(i + 1), 0, .5, downVi.frame.size.height)];
                blackVi.backgroundColor = [UIColor blackColor];
                [downVi addSubview:blackVi];
            }
            
            UILabel * titleLab = [[UILabel alloc] initWithFrame:CGRectMake(titleW * i, 0, titleW, 25)];
            titleLab.font = [UIFont systemFontOfSize:16];
            titleLab.text = [titleArr1 objectAtIndex:i];
            titleLab.textAlignment = NSTextAlignmentCenter;
            titleLab.backgroundColor = [UIColor clearColor];
            [downVi addSubview:titleLab];
            
            UILabel * label = [labArr objectAtIndex:i];
            label.frame = CGRectMake(titleW * i, 25, titleW, 25);
            label.font = [UIFont systemFontOfSize:16];
            if (i == 2) {
                label.text = @"0.00";
            }else{
                label.text = @"0.0";
            }
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor clearColor];
            [downVi addSubview:label];
        }
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
